package com.example.hehecat.yuejian1.ui.activity;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hehecat.yuejian1.R;
import com.example.hehecat.yuejian1.mvp.contract.UpdateMineContract;
import com.example.hehecat.yuejian1.mvp.presenter.UpdateMinePresenter;
import com.example.hehecat.yuejian1.ui.wiget.MyStaticVariable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UpdateMineActivity extends AppCompatActivity implements UpdateMineContract.View {


    @BindView(R.id.foodinfo_return)
    ImageView foodinfoReturn;
    @BindView(R.id.TextView)
    TextView TextView;
    @BindView(R.id.photo)
    ImageView photo;
    @BindView(R.id.nickname)
    EditText nickname1;
    @BindView(R.id.password)
    EditText password1;
    @BindView(R.id.address)
    EditText address1;
    @BindView(R.id.phone)
    EditText phone1;
    @BindView(R.id.ok)
    TextView ok;
    @BindView(R.id.password2)
    EditText password2;
    private UpdateMineContract.Presenter presenter;

    @OnClick(R.id.foodinfo_return)
    void UpdateReturn() {
        finish();
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_mine);
        ButterKnife.bind(this);
        presenter = new UpdateMinePresenter(UpdateMineActivity.this);


    }

    @OnClick(R.id.ok)
    void btOkOnClick() {
        if (isPWD()){
            int user_id = MyStaticVariable.newInstance().getUserid();
            String nickname = nickname1.getText().toString();
            String password = password1.getText().toString();
            String address = address1.getText().toString();
            String phone = phone1.getText().toString();
            presenter.updateMine(user_id, nickname, password, address, phone);
            finish();
        }else {
            return;
        }

    }

    @Override
    public void showdata(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }



    private boolean isPWD(){
        String str1 = password1.getText().toString();
        String str2 = password2.getText().toString();
        if (!str1.equals(str2)){
            showdata("密码错误");
            return false;
        }else {
            return true;
        }
    }
}
